#!/usr/bin/env python
# encoding: utf-8
'''
@author: Excelsiorly
@license: (C) Copyright 2021, All Rights Reserved.
@contact: excelsiorly@qq.com
@file: 0011.py
@time: 2021/9/13 10:59
@desc: https://leetcode-cn.com/problems/number-of-boomerangs/
'''
from collections import defaultdict


class Solution:
    def numberOfBoomerangs(self, points: list) -> int:
        ans = 0
        # 遍历每个点,作为中点pi
        for p in points:
            # 初始化一个带初始值0的字典，key为每次计算出的距离
            dis = defaultdict(int)
            # 继续遍历每个点，计算其到pi的距离
            for q in points:
                distance = (p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2
                # 将计算出的距离即key对应的项自增1，表示该距离下存在的点的个数
                dis[distance] += 1

            # 计算每个key下对应点的组合数 A(2, m) = m*(m-1)
            for m in dis.values():
                ans += m * (m - 1)

        return ans

if __name__ == '__main__':
    s = Solution()
    inp = [[0,0],[1,0],[2,0]]
    res = s.numberOfBoomerangs(inp)
    print(res)